<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/header.jsp" %>
<div class="row">
	<div class="col-xs-12">	
		<form id="menuForm" name="menuForm" class="form-horizontal" role="form">
		
					<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="menu_id1">菜单编号</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="menu_id1" name="menuId" readonly="readonly" class="col-xs-10  input-pk " value="${menu.menuId}"/>
					    </div>
					</div>
				</div>
				<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="menu_name1"><font color="red">*</font>菜单名称</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="menu_name1" name="menuName" class="col-xs-10  can-modify" value="${menu.menuName}"/>
					    </div>
					</div>
				</div>
					<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="is_leaf1">是否子菜单</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="is_leaf1" readonly="readonly" class="col-xs-10" value="<hw:dictName dictType='D00001' dictCode='${menu.isLeaf}'/>"/>
								<input type="hidden" name="isLeaf" class="can-modify" value="${menu.isLeaf}"/>
					    </div>
					</div>
				</div>
					<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="menu_url1"><font color="red">*</font>菜单路径</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="menu_url1" name="menuUrl"  value="${menu.menuUrl}" class="col-xs-10 can-modify"/>
					    </div>
					</div>
				</div>
					<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="parent_menu1">父菜单</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="show_menu1" name="show_parentMenu" readonly="true" class="col-xs-10 can-modify" value="${parentMenuName}"/>
								<input type="hidden" id="parent_menu1" name="parentMenu" readonly class="col-xs-10 can-modify" value="${menu.parentMenu}"/>
					    </div>
					</div>
				</div>
					<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="menu_order1">排序号</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="menu_order1" name="menuOrder" class="col-xs-10  can-modify" value="${menu.menuOrder}"/>
					    </div>
					</div>
				</div>
					<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="menu_class1">菜单样式</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="menu_class1" name="menuClass" class="col-xs-10  can-modify" value="${menu.menuClass}"/>
					    </div>
					</div>
				</div>
				<div class="form-group">	
					<label class="col-sm-3 control-label no-padding-right" for="menu_class1">权限</label>
					<div class="col-sm-9">
						<div class="clearfix">
								<input type="text" id="permission1" name="permission" class="col-xs-10  can-modify" value="${menu.permission}"/>
					    </div>
					</div>
				</div>
		</form>
	</div>		
</div>
<script type="text/javascript">
var scripts = [null, null];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	
	if ("${flag}" != "add") {
		disabledAll("menuForm");			
	} 
	
	
	
	$('#menuForm').validate({
		errorElement: 'div',
		errorClass: 'help-block',
		focusInvalid: false,
		ignore: "",
		rules: {
			menuName: {
		          required: true,
		          stringMaxLength:30
		       },
		    menuId:{
		    	 required: true
		    },
		   
	    	menuUrl:{
		    	 required: true,
		    	 stringMaxLength:60
		    }
		},
	
		messages: {
			
		},
	
		submitHandler: function (form) {
		},
		invalidHandler: function (form) {
		}
	});
	
});


function initButtons() {
	if ("${flag}" == "add") {
		$("#btnMenuModify").hide();
		$("#btnMenuSave").show();
		$("#btnMenuDelete").hide();
		$("#btnMenuCancle").hide();
		$("#btnMenuClose").show();
		
		$("#btnSubModify").hide();
		$("#btnSubSave").show();
		$("#btnSubDelete").hide();
		$("#btnSubCancle").hide();
		$("#btnSubClose").show();	
	} else if("${flag}" == "show"){
		$("#btnMenuModify").show();
		$("#btnMenuSave").hide();
		$("#btnMenuDelete").show();
		$("#btnMenuCancle").hide();
		$("#btnMenuClose").show();
		
		$("#btnSubModify").show();
		$("#btnSubSave").hide();
		$("#btnSubDelete").show();
		$("#btnSubCancle").hide();
		$("#btnSubClose").show();
	}else{
		alert("${flag}");
	}

}

function cancle() {
	if(confirm("是否取消修改？")){
		$("#menuForm")[0].reset();
		initButtons();
		disabledAll("menuForm");
	}
}

function modify() {
	$("#menuForm .can-modify").attr("disabled", false);
	$("#menuForm .input-pk").attr("disabled", false).attr("readonly","readonly");	
}


function save() {
	//debugger;
	if(!$("#menuForm").valid())
		return;
	var url;
	if ("${flag}" == "add") {
		url = "${ctx}/menu/add";
	}else {
		url = "${ctx}/menu/modify";
	}
    		
	$.ajax({
		async : false,
		url: url,
		type:"post",
		data: $("#menuForm").serialize(),
		dataType:"json",
		success: function(ret){
			if (ret[0] == "ok") {
				alert(ret[1]);
				$("#menuIframe").dialog("close");
				$("#menuIframe").empty();
				$("#menuSubIframe").dialog("close");
				$("#menuSubIframe").empty();
				if('${menu.parentMenu}' == '' || '${menu.parentMenu}' == null){
					$("#menuList").load("${ctx}/menu/list"+"?temp="+new Date().getTime());
				}else{
					$("#menuSubListIframe").load("${ctx}/menu/list?parentId=" + '${menu.parentMenu}'+"&temp="+new Date().getTime());
				}				
			} else {
				alert(ret[1]);
			}				
		},
		error: function(ret){
			alert(ret.responseText);
		}
	}); 
}
</script>
